package com.conversationboard.api;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.SecurityContext;

import com.conversationboard.api.security.Security;


public class LogoutProcessor implements Processor {

	/* Input Form: <Logout></Logout> */

	@Override
	public String processXml(String xml, SecurityContext securityContext, HttpServletRequest request) throws ApiException {

		if (!Security.isLoggedIn(securityContext)) {
			return "<Logout><Error>Not logged in</Error></Logout>";
		}
		
		try {
			request.logout();
		} catch (ServletException e) {
			throw new ApiException(e);
		}

		return "<Logout>Success</Logout>";

	}

}
